{extend name="common/adminBase" /}
{block name="body"}

<body >
<div style="margin-top: 20px">

    <div style="text-align: center">
        <div class="layui-upload-drag" id="test10">
            <i class="layui-icon" style="font-size: 50px"></i>
            <p>点击上传,或将图片拖拽到此处,支持jpg,png</p>
            <div class="layui-hide" id="uploadDemoView">
                <hr>
                <img src="" alt="上传成功后渲染" style="max-width: 196px" id="banner">
            </div>
        </div>

    </div>
</div>


<script>
    //Demo
    layui.use(['form','upload','laydate'],function(){
        var form = layui.form
        ,upload = layui.upload;
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#test1' //指定元素
        });
        //拖拽上传
        upload.render({
            elem: '#test10'
            ,url: '/admin/WebConfig/addBanner' //改成您自己的上传接口
            ,accept: 'file'
            ,'field':'banner'
            ,done: function(res){
                if (res.status){
                    $("#banner").attr('src',res.msg)
                    layer.msg(res.msg,{icon:1,time:1500},function () {
                        xadmin.close();
                        // 可以对父窗口进行刷新
                        xadmin.father_reload();
                    });

                }
                console.log(res)
            }
        });

        //监听提交
        form.on('submit(formDemo)', function(data){
            $.ajax({
                url:'',
                data:data.field,
                type:'post',
                dataType:'json',
                success:function (res) {
                    if (res.status==1){
                        layer.msg(res.msg,{icon:1,time:1500},function(){
                            location.href='/admin/User/index'
                        })
                    }else{
                        layer.alert(res.msg,function(index){
                            layer.close(index)
                        })
                    }
                }
            })
            return false;
        });
    });
</script>
</body>
{/block}